package cate.game.activity.worldboss;

import cate.common.table.activity.worldboss.WorldBossBaseRow;
import cate.common.table.d.GDObj;
import cate.common.table.d.GDOperation;
import cate.game.activity.worldboss.msg.WorldBossChallengeResultResp;
import cate.game.play.proce.play.PlayPO;
import cate.game.res.MixRes;
import cate.game.res.MixResAdder;
import cate.game.res.MixResItem;
import cate.game.role.Role;
import cate.game.role.farm.AbstractFarmFTC;

public class WorldBossFTC extends AbstractFarmFTC<RoleWorldBoss> {
    /**
     * 当前挑战关卡的模板
     */
    private final WorldBossBaseRow row;

    public WorldBossFTC(Role role,int funcId, WorldBossBaseRow row) {
        this.funcId = funcId;
        this.row = row;
        setup(role);
    }

    @Override
    protected RoleWorldBoss po(Role role) {
        return role.getActivity().getEnableActivitySingle(funcId);
    }

    @Override
    public void handleResult(Role role, PlayPO play) {
        super.handleResult(role, play);
        double damage = play.teamEnd.b.getAllHero().get(0).performance.hurt;
        int exNum = (int) (damage / row.coeff);
        if (exNum < 0) {
            exNum = 0;
        }
        int rwdNum = Math.min(row.baseNum + exNum, row.maxNum);
        MixRes reward = new MixRes();
        reward.addList(new MixRes(row.fixRwdCode));
        reward.addItem(new MixResItem(GDObj.Type.PROP, row.rwdTid, rwdNum));
        new MixResAdder().setOperation(GDOperation.WORLD_BOSS_CHALLENGE).setRes(reward).exe(role);
        WorldBossChallengeResultResp resp = new WorldBossChallengeResultResp(funcId, reward,damage);
        role.sendNow(resp);
    }
}
